<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>归档和压缩 | 皮卡车</title>
    <meta name="description" content="皮卡车的文档, vuepress 文档">
    <meta name="generator" content="VuePress 1.3.1">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  <link rel="icon" href="/favicon.ico">
  <link rel="manifest" href="/manifest.json">
  <meta name="theme-color" content="#ffffff">
  <meta name="google-site-verification" content="Ld_AEWr30siza2LmmZ12csitRGsSj9gqqEAch0UXkTc">
    
    <link rel="preload" href="/assets/css/0.styles.1a6a4f51.css" as="style"><link rel="preload" href="/assets/js/app.1f0f93c9.js" as="script"><link rel="preload" href="/assets/js/2.f28f3227.js" as="script"><link rel="preload" href="/assets/js/98.7aa56ed0.js" as="script"><link rel="preload" href="/assets/js/3.a7eaa85f.js" as="script"><link rel="prefetch" href="/assets/js/10.7b76d38f.js"><link rel="prefetch" href="/assets/js/100.0d62a3f6.js"><link rel="prefetch" href="/assets/js/101.4916ac0c.js"><link rel="prefetch" href="/assets/js/102.0ee21f66.js"><link rel="prefetch" href="/assets/js/103.872c594c.js"><link rel="prefetch" href="/assets/js/104.0bff815e.js"><link rel="prefetch" href="/assets/js/105.46330c43.js"><link rel="prefetch" href="/assets/js/106.4ad211ca.js"><link rel="prefetch" href="/assets/js/107.d9011871.js"><link rel="prefetch" href="/assets/js/108.bab8ed0e.js"><link rel="prefetch" href="/assets/js/109.b7e4a790.js"><link rel="prefetch" href="/assets/js/11.518e0dbb.js"><link rel="prefetch" href="/assets/js/110.1eb492e8.js"><link rel="prefetch" href="/assets/js/111.ee6a2e31.js"><link rel="prefetch" href="/assets/js/112.05d655c6.js"><link rel="prefetch" href="/assets/js/113.0a4cf8f0.js"><link rel="prefetch" href="/assets/js/114.ef783947.js"><link rel="prefetch" href="/assets/js/115.11bbdb9c.js"><link rel="prefetch" href="/assets/js/116.5646126d.js"><link rel="prefetch" href="/assets/js/117.854d26bf.js"><link rel="prefetch" href="/assets/js/118.1e514b13.js"><link rel="prefetch" href="/assets/js/119.aa944f45.js"><link rel="prefetch" href="/assets/js/12.511e3547.js"><link rel="prefetch" href="/assets/js/120.1c6f450c.js"><link rel="prefetch" href="/assets/js/121.44f16ee6.js"><link rel="prefetch" href="/assets/js/122.f877b8e8.js"><link rel="prefetch" href="/assets/js/123.0563fdd5.js"><link rel="prefetch" href="/assets/js/124.4cd97316.js"><link rel="prefetch" href="/assets/js/125.a502f4ee.js"><link rel="prefetch" href="/assets/js/126.c7e94093.js"><link rel="prefetch" href="/assets/js/127.bd8aed7f.js"><link rel="prefetch" href="/assets/js/128.66063cc3.js"><link rel="prefetch" href="/assets/js/129.21bb1073.js"><link rel="prefetch" href="/assets/js/13.9e5bee4e.js"><link rel="prefetch" href="/assets/js/130.c8edfccb.js"><link rel="prefetch" href="/assets/js/131.7a1f29be.js"><link rel="prefetch" href="/assets/js/132.f589fc06.js"><link rel="prefetch" href="/assets/js/133.55ac5c9a.js"><link rel="prefetch" href="/assets/js/134.eeab127b.js"><link rel="prefetch" href="/assets/js/135.5a1571dd.js"><link rel="prefetch" href="/assets/js/136.b72b4d1c.js"><link rel="prefetch" href="/assets/js/137.678e022a.js"><link rel="prefetch" href="/assets/js/138.ba4108fa.js"><link rel="prefetch" href="/assets/js/139.0b02b599.js"><link rel="prefetch" href="/assets/js/14.b9ec07e6.js"><link rel="prefetch" href="/assets/js/140.690e4e4c.js"><link rel="prefetch" href="/assets/js/141.709da4ed.js"><link rel="prefetch" href="/assets/js/142.f2de76c0.js"><link rel="prefetch" href="/assets/js/143.4dcb17f0.js"><link rel="prefetch" href="/assets/js/144.730ef429.js"><link rel="prefetch" href="/assets/js/145.d881c754.js"><link rel="prefetch" href="/assets/js/146.f3379a41.js"><link rel="prefetch" href="/assets/js/147.eeb9ca6f.js"><link rel="prefetch" href="/assets/js/148.bb6020cd.js"><link rel="prefetch" href="/assets/js/149.1d34dea6.js"><link rel="prefetch" href="/assets/js/15.d0fa1a9d.js"><link rel="prefetch" href="/assets/js/150.599238ba.js"><link rel="prefetch" href="/assets/js/151.9655268f.js"><link rel="prefetch" href="/assets/js/152.1f843fa4.js"><link rel="prefetch" href="/assets/js/153.7af45ca6.js"><link rel="prefetch" href="/assets/js/154.eff93a56.js"><link rel="prefetch" href="/assets/js/155.ff07fba4.js"><link rel="prefetch" href="/assets/js/156.1b1814b7.js"><link rel="prefetch" href="/assets/js/157.8ac4c21b.js"><link rel="prefetch" href="/assets/js/158.aa8a0124.js"><link rel="prefetch" href="/assets/js/159.d61fdb37.js"><link rel="prefetch" href="/assets/js/16.ccd2bd60.js"><link rel="prefetch" href="/assets/js/17.ddc8fde4.js"><link rel="prefetch" href="/assets/js/18.a06e60cc.js"><link rel="prefetch" href="/assets/js/19.64b3dec9.js"><link rel="prefetch" href="/assets/js/20.3615e182.js"><link rel="prefetch" href="/assets/js/21.0c654d53.js"><link rel="prefetch" href="/assets/js/22.720aac8f.js"><link rel="prefetch" href="/assets/js/23.0dc53b91.js"><link rel="prefetch" href="/assets/js/24.d4b75b0e.js"><link rel="prefetch" href="/assets/js/25.9120702e.js"><link rel="prefetch" href="/assets/js/26.b24d89e2.js"><link rel="prefetch" href="/assets/js/27.55df94ab.js"><link rel="prefetch" href="/assets/js/28.250c68a5.js"><link rel="prefetch" href="/assets/js/29.75a3c8f3.js"><link rel="prefetch" href="/assets/js/30.8cdc2fcd.js"><link rel="prefetch" href="/assets/js/31.45303d68.js"><link rel="prefetch" href="/assets/js/32.f4225739.js"><link rel="prefetch" href="/assets/js/33.15b21267.js"><link rel="prefetch" href="/assets/js/34.5baca30b.js"><link rel="prefetch" href="/assets/js/35.5d9dfab1.js"><link rel="prefetch" href="/assets/js/36.981eadca.js"><link rel="prefetch" href="/assets/js/37.cead7f6b.js"><link rel="prefetch" href="/assets/js/38.ee6bcaf1.js"><link rel="prefetch" href="/assets/js/39.e7579788.js"><link rel="prefetch" href="/assets/js/4.494c614b.js"><link rel="prefetch" href="/assets/js/40.01d2b30b.js"><link rel="prefetch" href="/assets/js/41.19cf06ce.js"><link rel="prefetch" href="/assets/js/42.15941cde.js"><link rel="prefetch" href="/assets/js/43.66adb73c.js"><link rel="prefetch" href="/assets/js/44.8d99ed62.js"><link rel="prefetch" href="/assets/js/45.12ea9159.js"><link rel="prefetch" href="/assets/js/46.644efa88.js"><link rel="prefetch" href="/assets/js/47.531131c7.js"><link rel="prefetch" href="/assets/js/48.b214f000.js"><link rel="prefetch" href="/assets/js/49.e42d4b72.js"><link rel="prefetch" href="/assets/js/5.7e277dc8.js"><link rel="prefetch" href="/assets/js/50.de0aa85c.js"><link rel="prefetch" href="/assets/js/51.8be2974c.js"><link rel="prefetch" href="/assets/js/52.cc067888.js"><link rel="prefetch" href="/assets/js/53.4ceb2c6b.js"><link rel="prefetch" href="/assets/js/54.b2647058.js"><link rel="prefetch" href="/assets/js/55.dc3df953.js"><link rel="prefetch" href="/assets/js/56.921a6934.js"><link rel="prefetch" href="/assets/js/57.1e24b1fd.js"><link rel="prefetch" href="/assets/js/58.f4e8ebac.js"><link rel="prefetch" href="/assets/js/59.17ab117b.js"><link rel="prefetch" href="/assets/js/6.4014218f.js"><link rel="prefetch" href="/assets/js/60.352cea9b.js"><link rel="prefetch" href="/assets/js/61.77289388.js"><link rel="prefetch" href="/assets/js/62.ec0ed919.js"><link rel="prefetch" href="/assets/js/63.c75dcb25.js"><link rel="prefetch" href="/assets/js/64.59d15a75.js"><link rel="prefetch" href="/assets/js/65.7e5a14bb.js"><link rel="prefetch" href="/assets/js/66.4e770ba1.js"><link rel="prefetch" href="/assets/js/67.0742f21a.js"><link rel="prefetch" href="/assets/js/68.a6ed34fd.js"><link rel="prefetch" href="/assets/js/69.48c9a47f.js"><link rel="prefetch" href="/assets/js/7.c5ecd7d3.js"><link rel="prefetch" href="/assets/js/70.eb477192.js"><link rel="prefetch" href="/assets/js/71.1be57009.js"><link rel="prefetch" href="/assets/js/72.6859561c.js"><link rel="prefetch" href="/assets/js/73.aae65018.js"><link rel="prefetch" href="/assets/js/74.59d76d34.js"><link rel="prefetch" href="/assets/js/75.04e23427.js"><link rel="prefetch" href="/assets/js/76.74d6eb6a.js"><link rel="prefetch" href="/assets/js/77.fba76057.js"><link rel="prefetch" href="/assets/js/78.0da94b25.js"><link rel="prefetch" href="/assets/js/79.14676976.js"><link rel="prefetch" href="/assets/js/8.08c85334.js"><link rel="prefetch" href="/assets/js/80.7494721f.js"><link rel="prefetch" href="/assets/js/81.f04f6229.js"><link rel="prefetch" href="/assets/js/82.e4c6f74b.js"><link rel="prefetch" href="/assets/js/83.81ad8dbf.js"><link rel="prefetch" href="/assets/js/84.d28e4a3d.js"><link rel="prefetch" href="/assets/js/85.d99fa7fa.js"><link rel="prefetch" href="/assets/js/86.597ecadb.js"><link rel="prefetch" href="/assets/js/87.e6d21734.js"><link rel="prefetch" href="/assets/js/88.b43a52d4.js"><link rel="prefetch" href="/assets/js/89.a5ba287d.js"><link rel="prefetch" href="/assets/js/9.658cd6b3.js"><link rel="prefetch" href="/assets/js/90.c253df12.js"><link rel="prefetch" href="/assets/js/91.8946a93d.js"><link rel="prefetch" href="/assets/js/92.8b8f1ae0.js"><link rel="prefetch" href="/assets/js/93.aa73c784.js"><link rel="prefetch" href="/assets/js/94.9326bcc7.js"><link rel="prefetch" href="/assets/js/95.46b64b79.js"><link rel="prefetch" href="/assets/js/96.61a9b0b9.js"><link rel="prefetch" href="/assets/js/97.65a03aad.js"><link rel="prefetch" href="/assets/js/99.a652c8d5.js">
    <link rel="stylesheet" href="/assets/css/0.styles.1a6a4f51.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">皮卡车</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  Home
</a></div><div class="nav-item"><a href="/guide/" class="nav-link">
  Guide
</a></div><div class="nav-item"><a href="/computer/" class="nav-link">
  计算机
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="系统" class="dropdown-title"><span class="title">系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/os/linux/" class="nav-link router-link-active">
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/os/manjaro/" class="nav-link">
  Manjaro
</a></li><li class="dropdown-item"><!----> <a href="/os/ubuntu/" class="nav-link">
  Ubuntu
</a></li><li class="dropdown-item"><!----> <a href="/os/centos/" class="nav-link">
  CentOS
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><span class="title">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/frontend/javascript/" class="nav-link">
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="https://css.shanyuhai.top/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSS
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="/frontend/webpack/" class="nav-link">
  Webpack
</a></li><li class="dropdown-item"><!----> <a href="/frontend/d3js/" class="nav-link">
  D3
</a></li><li class="dropdown-item"><!----> <a href="/frontend/utils/" class="nav-link">
  Utils
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><span class="title">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/backend/nodejs/" class="nav-link">
  Nodejs
</a></li><li class="dropdown-item"><!----> <a href="/backend/koa/" class="nav-link">
  Koa
</a></li><li class="dropdown-item"><!----> <a href="/backend/mongodb/" class="nav-link">
  MongoDB
</a></li><li class="dropdown-item"><!----> <a href="/backend/nginx/" class="nav-link">
  Nginx
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/tools/git/" class="nav-link">
  Git
</a></li><li class="dropdown-item"><!----> <a href="/tools/github/" class="nav-link">
  Github
</a></li><li class="dropdown-item"><!----> <a href="/tools/vscode/" class="nav-link">
  VSCode
</a></li><li class="dropdown-item"><!----> <a href="/tools/chrome/" class="nav-link">
  Chrome Developer tools
</a></li><li class="dropdown-item"><!----> <a href="/tools/bookmark-scripts/" class="nav-link">
  Bookmark scripts
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><span class="title">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/more/algorithm/" class="nav-link">
  算法
</a></li><li class="dropdown-item"><!----> <a href="/more/interview/" class="nav-link">
  面试题
</a></li><li class="dropdown-item"><!----> <a href="/more/hodgepodge/" class="nav-link">
  大杂烩
</a></li><li class="dropdown-item"><!----> <a href="/more/clean/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="https://v1.vuepress.vuejs.org/zh/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  VuePress1.x 官网
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  Home
</a></div><div class="nav-item"><a href="/guide/" class="nav-link">
  Guide
</a></div><div class="nav-item"><a href="/computer/" class="nav-link">
  计算机
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="系统" class="dropdown-title"><span class="title">系统</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/os/linux/" class="nav-link router-link-active">
  Linux
</a></li><li class="dropdown-item"><!----> <a href="/os/manjaro/" class="nav-link">
  Manjaro
</a></li><li class="dropdown-item"><!----> <a href="/os/ubuntu/" class="nav-link">
  Ubuntu
</a></li><li class="dropdown-item"><!----> <a href="/os/centos/" class="nav-link">
  CentOS
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><span class="title">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/frontend/javascript/" class="nav-link">
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="https://css.shanyuhai.top/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSS
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li><li class="dropdown-item"><!----> <a href="/frontend/webpack/" class="nav-link">
  Webpack
</a></li><li class="dropdown-item"><!----> <a href="/frontend/d3js/" class="nav-link">
  D3
</a></li><li class="dropdown-item"><!----> <a href="/frontend/utils/" class="nav-link">
  Utils
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="后端" class="dropdown-title"><span class="title">后端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/backend/nodejs/" class="nav-link">
  Nodejs
</a></li><li class="dropdown-item"><!----> <a href="/backend/koa/" class="nav-link">
  Koa
</a></li><li class="dropdown-item"><!----> <a href="/backend/mongodb/" class="nav-link">
  MongoDB
</a></li><li class="dropdown-item"><!----> <a href="/backend/nginx/" class="nav-link">
  Nginx
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/tools/git/" class="nav-link">
  Git
</a></li><li class="dropdown-item"><!----> <a href="/tools/github/" class="nav-link">
  Github
</a></li><li class="dropdown-item"><!----> <a href="/tools/vscode/" class="nav-link">
  VSCode
</a></li><li class="dropdown-item"><!----> <a href="/tools/chrome/" class="nav-link">
  Chrome Developer tools
</a></li><li class="dropdown-item"><!----> <a href="/tools/bookmark-scripts/" class="nav-link">
  Bookmark scripts
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><span class="title">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/more/algorithm/" class="nav-link">
  算法
</a></li><li class="dropdown-item"><!----> <a href="/more/interview/" class="nav-link">
  面试题
</a></li><li class="dropdown-item"><!----> <a href="/more/hodgepodge/" class="nav-link">
  大杂烩
</a></li><li class="dropdown-item"><!----> <a href="/more/clean/" class="nav-link">
  风格指南
</a></li><li class="dropdown-item"><!----> <a href="https://v1.vuepress.vuejs.org/zh/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  VuePress1.x 官网
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>LINUX</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/os/linux/" class="sidebar-link">首页</a></li><li><a href="/os/linux/everything-is-a-file.html" class="sidebar-link">一切皆文件</a></li><li><a href="/os/linux/alias.html" class="sidebar-link">别名 alias</a></li><li><a href="/os/linux/ansible.html" class="sidebar-link">分发脚本 ansible</a></li><li><a href="/os/linux/archiving-and-compression.html" class="active sidebar-link">归档和压缩</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/os/linux/archiving-and-compression.html#介绍" class="sidebar-link">介绍</a></li><li class="sidebar-sub-header"><a href="/os/linux/archiving-and-compression.html#tar" class="sidebar-link">tar</a></li><li class="sidebar-sub-header"><a href="/os/linux/archiving-and-compression.html#zip" class="sidebar-link">zip</a></li><li class="sidebar-sub-header"><a href="/os/linux/archiving-and-compression.html#gzip" class="sidebar-link">gzip</a></li><li class="sidebar-sub-header"><a href="/os/linux/archiving-and-compression.html#bzip2" class="sidebar-link">bzip2</a></li></ul></li><li><a href="/os/linux/command-options.html" class="sidebar-link">命令选项</a></li><li><a href="/os/linux/command-shortcut.html" class="sidebar-link">命令行快捷键</a></li><li><a href="/os/linux/crontab.html" class="sidebar-link">解放双手计划</a></li><li><a href="/os/linux/detect-your-server.html" class="sidebar-link">检测服务器通达</a></li><li><a href="/os/linux/directory-structure.html" class="sidebar-link">目录结构</a></li><li><a href="/os/linux/firewalld.html" class="sidebar-link">防火墙 firewalld</a></li><li><a href="/os/linux/gaudy-and-pragmatical-command.html" class="sidebar-link">花里胡哨且实用的命令</a></li><li><a href="/os/linux/generate-ssh-key.html" class="sidebar-link">创建 SSH Key</a></li><li><a href="/os/linux/grep-sed-awk.html" class="sidebar-link">文本三剑客</a></li><li><a href="/os/linux/how-to-enable-the-hard-disk.html" class="sidebar-link">如何启用硬盘</a></li><li><a href="/os/linux/how-to-install-linux-on-virtualbox.html" class="sidebar-link">虚拟机中安装 Linux</a></li><li><a href="/os/linux/io-redirection.html" class="sidebar-link">输入、输出重定向</a></li><li><a href="/os/linux/login-with-rsa-key.html" class="sidebar-link">使用 RSA 登录服务器</a></li><li><a href="/os/linux/raid.html" class="sidebar-link">磁盘阵列</a></li><li><a href="/os/linux/rsync-and-scp.html" class="sidebar-link">远程同步文件</a></li><li><a href="/os/linux/systemd.html" class="sidebar-link">守护系统 systemd</a></li><li><a href="/os/linux/user.html" class="sidebar-link">用户管理</a></li><li><a href="/os/linux/view-text-context.html" class="sidebar-link">查看文本内容</a></li><li><a href="/os/linux/xargs.html" class="sidebar-link">传参 xargs</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h2 id="介绍"><a href="#介绍" class="header-anchor">#</a> 介绍</h2> <p>归档（打包）和压缩是两步（曾经以为是一步操作），先执行归档，再执行压缩。</p> <p>归档，指的是一个或多个文件或目录的合集，被存储在一个文件中。因此，该文件所占用的空间是其中所有文件和目录的总和。</p> <p><a href="https://zh.wikipedia.org/wiki/%E6%95%B0%E6%8D%AE%E5%8E%8B%E7%BC%A9" target="_blank" rel="noopener noreferrer">压缩<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>，是利用算法字典对归档的文件进行处理，实现保留最大的文件信息，缩小文件体积。基本原理为，查找文件内的重复字节、连续字节（这也是首先需要归档的原因），从而建立字典文件，压缩时进行替换，当然压缩算法一直在在进步的，详情可查阅相关资料。压缩分为有损压缩和无损压缩，有损压缩常用于音视频图像文件。</p> <h2 id="tar"><a href="#tar" class="header-anchor">#</a> tar</h2> <p>最常用的归档（打包）命令就是 tar，该命令可以将多个文件保存到一个文件中。该命令还可以从归档文件中还原所需文件，也就是解包。</p> <h3 id="_1-命令格式"><a href="#_1-命令格式" class="header-anchor">#</a> 1. 命令格式</h3> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>tar [选项...] [FILE]...</p></div> <h3 id="_2-常用选项"><a href="#_2-常用选项" class="header-anchor">#</a> 2. 常用选项</h3> <table><thead><tr><th style="text-align:center;">选项</th> <th style="text-align:center;">含义</th></tr></thead> <tbody><tr><td style="text-align:center;">-c</td> <td style="text-align:center;">将多个文件或目录进行打包。</td></tr> <tr><td style="text-align:center;">-x</td> <td style="text-align:center;">对 tar 包进行解包操作。</td></tr> <tr><td style="text-align:center;">-A</td> <td style="text-align:center;">追加 tar 文件到归档文件。</td></tr> <tr><td style="text-align:center;">-f 包名</td> <td style="text-align:center;">指定包的文件名。包的扩展名是用来给管理员识别格式的，所以一定要正确指定扩展名。</td></tr> <tr><td style="text-align:center;">-v</td> <td style="text-align:center;">显示打包/解包文件过程。</td></tr> <tr><td style="text-align:center;">-t</td> <td style="text-align:center;">只查看 tar 包中有哪些文件，不对 tar 包做解包操作。</td></tr> <tr><td style="text-align:center;">-C</td> <td style="text-align:center;">指定解包位置。</td></tr></tbody></table> <h3 id="_3-示例"><a href="#_3-示例" class="header-anchor">#</a> 3. 示例</h3> <ul><li><p>打包文件和目录：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 文件</span>
<span class="token function">tar</span> -cvf test.md.tar test.md
<span class="token function">ls</span> <span class="token comment"># 验证</span>
<span class="token comment"># 目录</span>
<span class="token function">mkdir</span> <span class="token builtin class-name">test</span>
<span class="token function">touch</span> test/test<span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">..</span><span class="token number">3</span><span class="token punctuation">}</span>.txt
tree <span class="token builtin class-name">test</span> <span class="token comment"># 验证</span>
<span class="token function">tar</span> -cvf testfile.tar test/
<span class="token function">ls</span> <span class="token comment"># 验证</span>
</code></pre></div></li> <li><p>解包文件：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 当前目录</span>
<span class="token function">tar</span> -xvf testfile.tar
tree <span class="token builtin class-name">test</span> <span class="token comment"># 验证</span>
<span class="token comment"># 指定目录</span>
<span class="token function">tar</span> -xvf testfile.tar -C <span class="token builtin class-name">test</span>
tree <span class="token builtin class-name">test</span> <span class="token comment"># 验证</span>
<span class="token comment"># 仅查看压缩包中有哪些文件，不解包</span>
<span class="token function">tar</span> -tvf testfile.tar
</code></pre></div></li></ul> <h3 id="_4-加强"><a href="#_4-加强" class="header-anchor">#</a> 4. 加强</h3> <p>其实 tar 也可以同时打包压缩。常用的选项有两个：</p> <ul><li>-z：压缩和解压 <code>.tar.gz</code> 格式；</li> <li>-j：压缩和解压 <code>.tar.bz2</code> 格式。</li></ul> <p>添加上压缩、解压的操作为：</p> <ul><li><p>打包压缩</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">tar</span> -zcvf testfile.tar.gz <span class="token builtin class-name">test</span>
<span class="token function">tar</span> -tvf testfile.tar.gz <span class="token comment"># 验证</span>

<span class="token comment"># bz2 格式</span>
<span class="token function">tar</span> -jcvf testfile.tar.bz2 <span class="token builtin class-name">test</span>
</code></pre></div></li> <li><p>解压解包</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">tar</span> -zxvf testfile.tar.gz
tree <span class="token builtin class-name">test</span> <span class="token comment"># 验证</span>

<span class="token comment"># bz2 格式</span>
<span class="token function">tar</span> -jxvf testfile.tar.bz2
</code></pre></div></li></ul> <h2 id="zip"><a href="#zip" class="header-anchor">#</a> zip</h2> <p>zip 是几种主流的压缩格式之一。与之对应的是 unzip。</p> <h3 id="_1-命令格式-2"><a href="#_1-命令格式-2" class="header-anchor">#</a> 1. 命令格式</h3> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>zip [选项...] 压缩包名 源文件或源目录</p></div> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>unzip [选项] 压缩包名</p></div> <h3 id="_2-常用选项-2"><a href="#_2-常用选项-2" class="header-anchor">#</a> 2. 常用选项</h3> <p>zip 常用选项：</p> <table><thead><tr><th style="text-align:center;">选项</th> <th style="text-align:center;">含义</th></tr></thead> <tbody><tr><td style="text-align:center;">-r</td> <td style="text-align:center;">递归压缩目录，及将制定目录下的所有文件以及子目录全部压缩。</td></tr> <tr><td style="text-align:center;">-m</td> <td style="text-align:center;">将文件压缩之后，删除原始文件，相当于把文件移到压缩文件中。</td></tr> <tr><td style="text-align:center;">-v</td> <td style="text-align:center;">显示详细的压缩过程信息。</td></tr> <tr><td style="text-align:center;">-q</td> <td style="text-align:center;">在压缩的时候不显示命令的执行过程。</td></tr> <tr><td style="text-align:center;">-压缩级别</td> <td style="text-align:center;">压缩级别是从 1~9 的数字，-1 代表压缩速度更快，-9 代表压缩效果更好。</td></tr> <tr><td style="text-align:center;">-u</td> <td style="text-align:center;">更新压缩文件，即往压缩文件中添加新文件。</td></tr></tbody></table> <p>unzip 常用选项：</p> <table><thead><tr><th style="text-align:center;">选项</th> <th style="text-align:center;">含义</th></tr></thead> <tbody><tr><td style="text-align:center;">-d</td> <td style="text-align:center;">将压缩文件解压到指定目录下。</td></tr> <tr><td style="text-align:center;">-n</td> <td style="text-align:center;">解压时并不覆盖已经存在的文件。</td></tr> <tr><td style="text-align:center;">-o</td> <td style="text-align:center;">解压时覆盖已经存在的文件，并且无需用户确认。</td></tr> <tr><td style="text-align:center;">-v</td> <td style="text-align:center;">查看压缩文件的详细信息，但并不做解压操作。</td></tr> <tr><td style="text-align:center;">-t</td> <td style="text-align:center;">测试压缩文件有无损坏，但并不解压。</td></tr> <tr><td style="text-align:center;">-x  文件列表</td> <td style="text-align:center;">解压文件，但不包含文件列表中指定的文件。</td></tr></tbody></table> <h3 id="_3-示例-2"><a href="#_3-示例-2" class="header-anchor">#</a> 3. 示例</h3> <ul><li><p>打包压缩文件和目录：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 文件（多个文件不需要 -r）</span>
<span class="token function">zip</span> testfile.zip test.txt
<span class="token function">ls</span> -l testfile.zip <span class="token comment"># 验证</span>
<span class="token comment"># 目录</span>
<span class="token function">zip</span> -r testfile.zip <span class="token builtin class-name">test</span>
<span class="token function">ls</span> -l testfile.zip <span class="token comment"># 验证</span>
</code></pre></div></li> <li><p>解压解包：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 当前目录</span>
<span class="token function">unzip</span> testfile.zip
tree <span class="token builtin class-name">test</span> <span class="token comment"># 验证</span>
<span class="token comment"># 指定目录</span>
<span class="token function">unzip</span> testfile.zip -d test/test
tree <span class="token builtin class-name">test</span> <span class="token comment"># 验证</span>
</code></pre></div></li></ul> <h2 id="gzip"><a href="#gzip" class="header-anchor">#</a> gzip</h2> <p>gzip 是用来对文件进行压缩和解压的命令，其扩展为 <code>.gz</code>，gzip 一般需要配合 tar 使用（归档为文件），因为其只能压缩文件，即使指定了目录也只能压缩目录内的文件。与之对应的是 gunzip。</p> <h3 id="_1-命令格式-3"><a href="#_1-命令格式-3" class="header-anchor">#</a> 1. 命令格式</h3> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>gzip [选项] 源文件</p></div> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>gunzip [选项] 源文件</p></div> <h3 id="_2-常用选项-3"><a href="#_2-常用选项-3" class="header-anchor">#</a> 2. 常用选项</h3> <p>gzip 常用选项：</p> <table><thead><tr><th>选项</th> <th style="text-align:center;">含义</th></tr></thead> <tbody><tr><td>-c</td> <td style="text-align:center;">将压缩数据输出到标准输出中，并保留源文件。</td></tr> <tr><td>-r</td> <td style="text-align:center;">递归压缩指定目录下以及子目录下的所有文件。</td></tr> <tr><td>-v</td> <td style="text-align:center;">对于每个压缩和解压缩的文件，显示相应的文件名和压缩比。</td></tr> <tr><td>-l</td> <td style="text-align:center;">显示以下字段： 压缩文件的大小；未压缩文件的大小；压缩比；未压缩文件的名称。</td></tr> <tr><td>-数字</td> <td style="text-align:center;">用于指定压缩等级，-1 压缩等级最低；-9 压缩比最高。默认压缩比是 -6。</td></tr> <tr><td>-d</td> <td style="text-align:center;">对压缩文件进行解压缩。</td></tr></tbody></table> <p>gunzip 常用选项：</p> <table><thead><tr><th style="text-align:center;">选项</th> <th style="text-align:center;">含义</th></tr></thead> <tbody><tr><td style="text-align:center;">-r</td> <td style="text-align:center;">递归处理，解压缩指定目录下以及子目录下的所有文件。</td></tr> <tr><td style="text-align:center;">-c</td> <td style="text-align:center;">把解压缩后的文件输出到标准输出设备。</td></tr> <tr><td style="text-align:center;">-f</td> <td style="text-align:center;">强制解压缩文件，不理会文件是否已存在等情况。</td></tr> <tr><td style="text-align:center;">-l</td> <td style="text-align:center;">列出压缩文件内容。</td></tr> <tr><td style="text-align:center;">-v</td> <td style="text-align:center;">显示命令执行过程。</td></tr> <tr><td style="text-align:center;">-t</td> <td style="text-align:center;">测试压缩文件是否正常，但不对其做解压缩操作。</td></tr></tbody></table> <h3 id="_3-示例-3"><a href="#_3-示例-3" class="header-anchor">#</a> 3. 示例</h3> <ul><li><p>压缩文件：</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token comment"># 移除源文件</span>
<span class="token function">gzip</span>  test.txt
<span class="token function">ls</span> -l test.txt.gz <span class="token comment"># 验证</span>
<span class="token comment"># 保留源文件</span>
<span class="token function">gzip</span> -c test.txt <span class="token operator">&gt;</span>test.txt.gz
<span class="token function">ls</span> -l test.txt test.txt.gz <span class="token comment"># 验证</span>
</code></pre></div></li> <li><p>压缩目录：</p> <p>并不能压缩目录，只能分别压缩目录内的文件。</p> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">gzip</span> -r <span class="token builtin class-name">test</span> <span class="token comment"># 切记，会递归压缩其中所有文件，小心</span>
tree <span class="token builtin class-name">test</span> <span class="token comment"># 验证</span>
<span class="token function">gzip</span> -rd <span class="token builtin class-name">test</span> <span class="token comment"># 撤销打包</span>
</code></pre></div></li> <li><p>解压：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>gunzip test.txt.gz
gunzip -r <span class="token builtin class-name">test</span> 
</code></pre></div></li></ul> <h2 id="bzip2"><a href="#bzip2" class="header-anchor">#</a> bzip2</h2> <p>bzip2 命令与 gzip 目录类似，只能对文件进行压缩，其扩展为 <code>.bz2</code>。从理论上来说， <code>.bz2</code> 算法更先进，压缩比更好，而 <code>.gz</code>  相对而言压缩耗时更短。</p> <h3 id="_1-命令格式-4"><a href="#_1-命令格式-4" class="header-anchor">#</a> 1. 命令格式</h3> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>bzip2 [选项] 源文件</p></div> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>bunzip2 [选项] 源文件</p></div> <h3 id="_2-常用选项-4"><a href="#_2-常用选项-4" class="header-anchor">#</a> 2. 常用选项</h3> <p>bzip2 常用选项：</p> <table><thead><tr><th style="text-align:center;">选项</th> <th style="text-align:center;">含义</th></tr></thead> <tbody><tr><td style="text-align:center;">-d</td> <td style="text-align:center;">执行解压缩，此时该选项后的源文件应为标记有 .bz2 后缀的压缩包文件。</td></tr> <tr><td style="text-align:center;">-k</td> <td style="text-align:center;">bzip2 在压缩或解压缩任务完成后，会删除原始文件，若要保留原始文件，可使用此选项。</td></tr> <tr><td style="text-align:center;">-f</td> <td style="text-align:center;">bzip2 在压缩或解压缩时，若输出文件与现有文件同名，默认不会覆盖现有文件，若使用此选项，则会强制覆盖现有文件。</td></tr> <tr><td style="text-align:center;">-t</td> <td style="text-align:center;">测试压缩包文件的完整性。</td></tr> <tr><td style="text-align:center;">-v</td> <td style="text-align:center;">压缩或解压缩文件时，显示详细信息。</td></tr> <tr><td style="text-align:center;">-数字</td> <td style="text-align:center;">这个参数和 gzip 命令的作用一样，用于指定压缩等级，-1 压缩等级最低，压缩比最差；-9 压缩比最高</td></tr></tbody></table> <p>bunzip2 常用选项：</p> <table><thead><tr><th style="text-align:center;">选项</th> <th style="text-align:center;">含义</th></tr></thead> <tbody><tr><td style="text-align:center;">-k</td> <td style="text-align:center;">解压缩后，默认会删除原来的压缩文件。若要保留压缩文件，需使用此参数。</td></tr> <tr><td style="text-align:center;">-f</td> <td style="text-align:center;">解压缩时，若输出的文件与现有文件同名时，默认不会覆盖现有的文件。若要覆盖，可使用此选项。</td></tr> <tr><td style="text-align:center;">-v</td> <td style="text-align:center;">显示命令执行过程。</td></tr> <tr><td style="text-align:center;">-L</td> <td style="text-align:center;">列出压缩文件内容。</td></tr></tbody></table> <h3 id="_3-示例-4"><a href="#_3-示例-4" class="header-anchor">#</a> 3. 示例</h3> <p>参考 gzip 示例即可。</p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2020年3月17日星期二下午2点47分</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/os/linux/ansible.html" class="prev">
        分发脚本 ansible
      </a></span> <span class="next"><a href="/os/linux/command-options.html">
        命令选项
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----><!----></div></div>
    <script src="/assets/js/app.1f0f93c9.js" defer></script><script src="/assets/js/2.f28f3227.js" defer></script><script src="/assets/js/98.7aa56ed0.js" defer></script><script src="/assets/js/3.a7eaa85f.js" defer></script>
  </body>
</html>
